package com.bdc.utils;

import java.util.StringTokenizer;

public class TokenUtils {

    public static int[] getIntArray(String s, String separator) {
        StringTokenizer tokens = new StringTokenizer(s, separator, false);
        int[] intArray = new int[tokens.countTokens()];

        for (int i = 0; tokens.hasMoreTokens(); i++) {
            intArray[i] = Integer.parseInt(tokens.nextToken());
        }

        return intArray;
    }

    public static long[] getLongArray(String s, String separator) {
        StringTokenizer tokens = new StringTokenizer(s, separator, false);
        long[] longArray = new long[tokens.countTokens()];

        for (int i = 0; tokens.hasMoreTokens(); i++) {
            longArray[i] = Long.parseLong(tokens.nextToken());
        }

        return longArray;
    }

    public static String[] getStringArray(String s, String separator) {
        StringTokenizer tokens = new StringTokenizer(s, separator, false);
        String[] stringArray = new String[tokens.countTokens()];

        for (int i = 0; tokens.hasMoreTokens(); i++) {
            stringArray[i] = tokens.nextToken();
        }

        return stringArray;
    }

    public static String getTokenString(int[] array, String separator) {
        String result = "";
        for (int i = 0; i < array.length; i++)
            if (i == array.length - 1)
                result += Integer.toString(array[i]);
            else
                result += Integer.toString(array[i]) + separator;
        return result;
    }

    public static String getTokenString(long[] array, String separator) {
        String result = "";
        for (int i = 0; i < array.length; i++)
            if (i == array.length - 1)
                result += Long.toString(array[i]);
            else
                result += Long.toString(array[i]) + separator;
        return result;
    }

    public static String getTokenString(String[] array, String separator) {
        String result = "";
        for (int i = 0; i < array.length; i++)
            if (i == array.length - 1)
                result += array[i];
            else
                result += array[i] + separator;
        return result;
    }
}
